define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'share/money/index' + location.search,
                    // add_url: 'share/money/add',
                    // edit_url: 'share/money/edit',
                    shareuser_url: 'share/user/index',//跳转到用户列表
                    // del_url: 'share/money/del',
                    multi_url: 'share/money/multi',
                    import_url: 'share/money/import',
                    table: 'share_money',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'money', title: __('Money'), operate:false},
                        {field: 'mutual_money', title: __('互助金'), operate:false},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'user.mobile', title: '手机号',operate:'LIKE',visible: false},
                        {field: 'user.mobile_xing', title: '手机号', operate:false},
                        {field: 'is_grant', title: __('状态'), searchList:{"0":__('未发放'),"1":__('已发放')}, formatter: Table.api.formatter.status},
                        {field: 'goods_id', title: __('Goods_id')},
                        {field: 'role', title: __('Role'), searchList: {"0":__('无'),"1":__('推广员'),"2":__('代言人'),"3":__('一星网店经销商'),"4":__('二星网店经销商'),"5":__('银牌经销商'),"6":__('金牌经销商'),"7":__('钻石经销商')}, formatter: Table.api.formatter.status},
                        {field: 'addtime', title: __('Addtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'type', title: __('Type'), searchList: {"1":__('零售收益'),"2":__('批发收益'),"3":__('日广告收益'),"4":__('周广告收益'),"7":__('日广告收益')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: '操作', table: table,
                            //events: Table.api.events.addtabs,
                            buttons: [
                                {
                                    name: 'shareuser',
                                    text: __('查看用户'),
                                    // icon: 'fa fa-list',
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'share/user/index?user_id={user_id}',
                                    refresh: true,
                                    visible:function(row){
                                        if((1==1)){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    }

                                }, {
                                    name: 'shareuser',
                                    text: __('查看订单'),
                                    // icon: 'fa fa-list',
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'shopro/order/order/index?alert_order_id={order_id}',
                                    refresh: true,
                                    visible:function(row){
                                        if((1==1)){
                                           // window.location.href ="/shopro/order/order/index?filter=" + JSON.stringify(filter) + "&op=" + JSON.stringify(op);
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    }

                                }
                            ],
                            formatter: Table.api.formatter.operate
                        },

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
